
pckage Demo;

abstract class Data {
    abstract public void DisplayValue();
}
// byte类
class Byte extends  Data
{
    double value;
    //构造方法
    Byte()
    {
        value=20172330%6;
    }
    //  显示value的值
    public void DisplayValue(){
        System.out.println (value);
    }
}
//short类
class Short extends  Data
{
    double value;

    Short()
    {
        value = 20172330 % 6;
    }

    public void DisplayValue() {
        System.out.println(value);
    }
}
//Boolean类
class Boolean extends  Data
{
    double value;

    Boolean()
    {
        value = 20172330 % 6;
    }

    public void DisplayValue()
    {
        System.out.println(value);
    }
}
// long类
class Long extends  Data
{
    double value;

    Long() {
        value = 20172330 % 6;
    }

    public void DisplayValue() {
        System.out.println(value);
    }
}
//float类
class Float extends  Data
{
    double value;

    Float()
    {
        value = 20172330 % 6;
    }

    public void DisplayValue()
    {
        System.out.println(value);
    }
}
//double类
class Double extends  Data
{
    double value;

    Double()
    {
        value = 20172330 % 6;
    }

    public void DisplayValue()
    {
        System.out.println(value);
    }
}

//抽象类 pattern classes
abstract class Factory
{
    abstract public Data CreateDataObject();//抽象方法
}

class ByteFactory extends Factory
{
    public Data CreateDataObject()
    {
        return new Byte();
    }
}

class ShortFactory extends Factory
{
    public Data CreateDataObject(){
        return new Short();
    }
}

class BooleanFactory extends Factory
{
    public Data CreateDataObject(){
        return new Boolean();
    }
}

class LongFactory extends Factory
{
    public Data CreateDataObject(){
        return new Long();
    }
}

class FloatFactory extends Factory
{
    public Data CreateDataObject(){
        return new Float();
    }
}

class DoubleFactory extends Factory
{
    public Data CreateDataObject(){
        return new Double();
    }
}

//Client  classes
class Document
{
    Data pd;
    Document(Factory pf)
    {
        pd = pf.CreateDataObject();
    }
    public void DisplayData(){
        pd.DisplayValue();
    }
}
//Test class
public class MyDoc{
    static Document a,b,c,d,e,f;
    public static void main(String[] args) {
        a = new Document(new ByteFactory());
        b = new Document(new ShortFactory());
        c = new Document(new BooleanFactory());
        d = new Document(new LongFactory());
        e = new Document(new FloatFactory());
        f = new Document(new DoubleFactory());
        a.DisplayData();
        b.DisplayData();
        c.DisplayData();
        d.DisplayData();
        e.DisplayData();
        f.DisplayData();
    }
}

